Copyright: Trapper Copyright® 1993-1994 Presley Computing


Trapper

Error Trap Code Generation

     Trapper is a Code Generation tool that is capable of reading Basic text files and generating standard error trapping for each procedure in the file.  The best way to find out what Trapper does is to try it.

     Trapper will not over-write your existing code.  Trapper will not over-write any existing file unless you tell it to do so.  Try it with this in mind and see how Trapper can work for you.

What Trapper Does...

When to use Trapper

Tips

Registering Trapper

Trapper is Simple!  Here is how to get started...

•	Select File command button

Click this button to get started.  A common dialog will be displayed.  Select the source file to "Trap" in the list and click on OK.
Another dialog will be displayed.  The proposed output file will be entered in the File Name field for you.  (Trapper automatically adds the .ERR extension to the source file name.)  If this is adequate, click on OK to close the dialog.  If the output file exists, Trapper will ask you if you want to over-write the file.  Select Yes if you want to over-write the file, or No to go back and choose another file name for the output.

•	Go

This command button will not be enabled until you first select Source and Output files.  Once it is enabled, click on this Command to start Trapper!
It's that easy!

•	Exit (Click this command button when you are done.)

When finished, you will need to load your project into Visual Basic.  To see the results of Trapper, Remove the original file from your project.  Then Add the "trapped" file, using the File Add menu.

Note: The default extension for Trapper files is .ERR, therefore they will not normally be displayed in Visual Basic's File Add menu.  In the File Type list, choose All Files to display the "trapped" files.

•	Important note:  Trapper assumes that you have the Global constants defined for the Visual Basic MsgBox function.  You need to have IDRETRY, IDABORT, IDIGNORE, MB_ICONEXCLAMATION, and MB_ABORTRETRYIGNORE defined as a minimum.  These constants are located in the CONSTANT.TXT file distributed with Visual Basic.


What Trapper Does...

The easiest way to find out what Trapper does is to use it.

Trapper reads your Basic source code (saved in text format) and adds standard error trapping to your programs.

For VBDOS folks, Trapper only adds error trapping to Procedures (Subs and Functions) and does not affect module level code.

Trapper reads the name of the Procedure from the Sub/Function line and uses the name of the procedure to create meaningful labels.

After finding a procedure, Trapper inserts an On Error Goto Trap_Procedure statement at the beginning of the procedure.  At the end of the procedure, it adds:

Exit Sub/Function ' to avoid the error trap if
                  ' no error exists.

Trap_Procedure:
    Select Case MsgBox("Unexpected Error: " + Error$, MB_ICONQUESTION + MB_ABORTRETRYIGNORE) ' all on one line
    Case IDABORT
        Exit Sub/Function
    Case IDRETRY
        Resume
    Case IDIGNORE
        Resume Next
    End Select
End Sub/Function

Trapper shows some intelligence!  Trapper will leave your special error handling procedures alone.  Trapper will replace any "On Error Goto 0" statements it finds with "On Error Goto Trap_Procedure" as appropriate.

This allows you to do in-line error checking in parts of your procedures while you are writing your code.  You can use On Error Goto 0 while developing your application so that VB will display any unexpected errors.  Then when you are done adding the error checking for all those errors that you might expect, you may run Trapper.  Trapper will add this standard error checking to handle any unexpected errors.


When to use Trapper

You will want to use Trapper for most projects...

But at the appropriate time.

"When is the appropriate time?"  Good question!

I suggest you use Trapper at the end of the development cycle.  Most developers prefer to leave general error trapping turned off until their project is about complete.  This allows you to see the errors happen, when they happen--Visual Basic will immediately stop and show you the offending code.  With general error trapping enabled, it would make a little more difficult to see the errors as the happen.

The purpose of Trapper is to guard against those unexpected errors and provide a graceful, professional way for your application to handle them.

How do I see where the error occurred AFTER I run Trapper?

After you run Trapper, all unexpected errors will result in a standard Message Box "Abort, Retry, Ignore?"  When this MsgBox is displayed, press Ctrl+Break.  Then click on the Retry button.  As soon as you click on Retry, Visual Basic will return to the Break mode and the line where the error occurred will be highlighted.


Tips

•	While developing your application, use "In-line" error checking.  Here is an example:

On Error Resume Next
f$ = Dir$("a:\myfile.dat")
e% = Err
On Error Goto 0
If e% Then
     ' process error e%
End If
   :

Later, when you run Trapper on this code, it will add generic error trapping to this procedure.  Trapper would change the On Error Goto 0 to On Error Goto ProcedureName_Error.  The "inline" error checking is left unaffected, but unexpected errors outside of this "inline" trapping will be handled by the Trapper generated code.

•	Don't run Trapper too soon and...

•	Remember what Trapper will do for you.

     Running Trapper too soon in the development cycle can make debugging your program difficult.  The VB IDE is provided to assist you in trapping errors.  If you have generic error trapping enabled in every procedure you are likely to miss obvious mistakes and get unpredictable results.  Include error checking where you see that obvious errors may occur, or can't be avoided.  (Drive Not Ready, for example.)
    Keep in mind, as you are coding, what Trapper will do for you at the "end game."  Think to yourself if the following message box will be adequate:

     Realize what options this message box gives your end users:

1	Abort:  Code will exit the current procedure and continue.

2	Retry:  Code will resume at the statement that caused the error.

3	Ignore:  Program execution will resume at the next statement following the statement that caused the error.

If these options, or a variation of them, are adequate for the procedure you are writing, then you need not write any special error checking into the procedure.  You can let Trapper add it later.

•	It is easy to change the Trapper generated code.  Often times an "Ignore" option is not acceptable.  Changing the generated code is normally easier than adding your own.

•	Good Project Management is required.  Trapper will not output the generated code to the same file name.  Therefore, you must Remove the old and Add the new.

Debugging after running Trapper

•	After running Trapper on a form or module, errors that occur will result in the Abort, Retry, Ignore message box.  To see where the error occurred, press Ctrl+Break while this message box is displayed.  Then click on the Retry button.

Visual Basic will enter the Break mode and the line that caused the error will be highlighted.


Registering Trapper

•	Register Trapper on CompuServe.  GO SWREG at the ! prompt.  Follow the instructions and register #2360.  Registration fee is $10.

•	Send Check or money order for $10 (U.S.)  to:

Presley Computing
29322 Mandetta Drive
Fair Oaks Ranch, TX 78006-4529

•	Trapper is not free software.  If you find it useful, please register your copy.

Registered users will receive unlimited technical support via CompuServe and a registered copy in your name.  Thank you.

(If you have already registered, thanks!)


common dialog

A standard set of Windows dialog boxes for opening and saving files, printing, choosing colors, etc.  CMDIALOG.VBX gives you access to these standard dialog boxes.


CONSTANT.TXT

CONSTANT.TXT is installed in the VB subdirectory.  If you can't find it, that's okay.  Read the VB on-line help MsgBox topic.  It describes these constants and displayes their values.  Be sure and add these, exactly as they are spelled here, to the declarations section of a module in your project.


enabled

Controls that appear "grayed out" are not enabled.  Clicking on these controls will have no affect.


Fair Oaks Ranch

Home of Presley Computing located just North of San Antonio, Texas.  You will sometimes see our address as Boerne (pronounced Bernie).  The Boerne Post Office services this area.


IDE

Integrated Development Environment


Presley Computing

A small software development and consulting company located in beautiful Fair Oaks Ranch, in the Hill Country of Texas.  We specialize in Visual Basic and Access programming, application automation, and small computer consulting.  Jack Presley, the owner, is the author of Trapper.


SWREG

Acronym for CompuServes Shareware Registration service.  If you would like to register your own copy of Trapper, GO SWREG at the ! prompt on CompuServe.  When prompted, register program #2360.  CompuServe will add the registration fee to regular billing and will notify me of your registration.  You will promptly receive your own registered copy of Trapper!  It's that easy.


Trapper

A program that generates BASIC error trapping routines for each procedure in a text source code file.


Visual Basic

Visual Basic refers to Microsoft Visual Basic for Windows and Microsoft Visual Basic for DOS.  Trapper will work with other Basic products, but generated code may need modification.  Regardless of the product, files must be saved in text format.  I am interested in the results you have using other products.